from appium import webdriver
from selenium.webdriver.common.by import By


desired_caps = dict()
# 手机参数
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.1'
desired_caps['deviceName'] = 'emulator-5554'
# 应用参数
desired_caps['appPackage'] = 'com.bjcsxq.chat.carfriend'
desired_caps['appActivity'] = '.module_main.activity.SplashActivity'

# 中文输入设置参数
desired_caps['unicodeKeyboard'] = True
desired_caps['resetKeyboard'] = True

class DriverTools:
    driver = None

    @classmethod
    def OpenDriver(cls):
        if cls.driver is None:
            cls.driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_caps)
        return cls.driver

    @classmethod
    def QuiteDriver(cls):
        if cls.driver is not None:
            cls.driver.quit()
            cls.driver = None


def execute_assert():
    return DriverTools.OpenDriver().find_element(By.ID, "com.bjcsxq.chat.carfriend:id/txt_msg").text

def click_btn():
    return DriverTools.OpenDriver().find_element(By.ID, "com.bjcsxq.chat.carfriend:id/btn_pos").click()